/**
 * Created by hk on 2017/9/27.
 */
/**销户
 * Created by evan on 2017/9/26.
 */
var comValidform=null;
var doubleValidationStatus=false;
var doubleValidation ={
    id:null,
    itemId:"",

    init:function () {
        doubleValidation.dataHandle(); // 数据初始化
        doubleValidation.submitHandle(); //表单提交的操作
    },


    /**
     * 数据的初始化
     */
    dataHandle:function () {
        doubleValidation.id = art.dialog.data('doubleValidationId');  //修改id
        doubleValidation.itemId = doubleValidation.id+"_Double_Validation";
        var ret = eval('(' + localStorage.getItem(doubleValidation.itemId) + ')');
        for(var i in ret){
            var text=ret[i];
            if(i=='keyName'){
                $('#com-addForm select[name="'+i+'"]').val(text);
            }else {
                $('#com-addForm input[name="'+i+'"]').val(text);
            }
        }
    },

    submitHandle:function () {
        comValidform = $(".com-addForm").Validform({
            dataType:{

            },
            tiptype:2,
            tipSweep:true,
            beforeSubmit:function () {
                var url = 'mgr/safetyCtrl/updateSafety';
                var params = jsUtils.serializeJson($('.com-addForm'));
                params.actUserId = userId;
                params.keyName = $('#com-addForm select[name="keyName"]').val();
                var cb = function(data){
                    alert(data.msg);
                    //成功返回
                    if(data.resultCode==200){
                        //关闭窗口并刷新数据
                        //art.dialog.close();
                        localStorage.removeItem(doubleValidation.itemId );
                        var singleObj = data.result;

                        localStorage.setItem(singleObj.id
                            + "_Double_Validation", JSON
                            .stringify(singleObj));
                        doubleValidationStatus=true;
                    }
                };
                sendApiNoLoadSync(url, params, cb, 'POST');
                return doubleValidationStatus;


            }

        })
    }




};
$(document).ready(function() {
    doubleValidation.init();
});

/**
 * 提交表单
 */
function submitForm(){
    comValidform.submitForm();
    return doubleValidationStatus;
}
